<template>
  <div class="flower-detail">
    <div class="container">
      <el-card class="detail-card">
        <div class="detail-header">
          <h1>{{ flowerDetail.name }}</h1>
          <div class="tags">
            <el-tag type="success">{{ flowerDetail.category }}</el-tag>
            <el-tag type="warning">{{ flowerDetail.region }}</el-tag>
            <el-tag type="danger">{{ flowerDetail.protectionLevel }}</el-tag>
          </div>
        </div>

        <div class="detail-content">
          <div class="image-section">
            <img :src="flowerDetail.image" :alt="flowerDetail.name" class="flower-image">
          </div>

          <div class="info-section">
            <div class="info-group">
              <h2>基本信息</h2>
              <p class="description">{{ flowerDetail.description }}</p>
              <div class="info-item">
                <i class="el-icon-location"></i>
                <span>生长地区：{{ flowerDetail.habitat }}</span>
              </div>
              <div class="info-item">
                <i class="el-icon-date"></i>
                <span>花期：{{ flowerDetail.bloomingSeason }}</span>
              </div>
            </div>

            <div class="info-group">
              <h2>分类信息</h2>
              <div class="info-item">
                <i class="el-icon-collection"></i>
                <span>科属：{{ flowerDetail.family }}</span>
              </div>
              <div class="info-item">
                <i class="el-icon-collection-tag"></i>
                <span>属：{{ flowerDetail.genus }}</span>
              </div>
              <div class="info-item">
                <i class="el-icon-collection-tag"></i>
                <span>种：{{ flowerDetail.species }}</span>
              </div>
            </div>

            <div class="info-group">
              <h2>分布区域</h2>
              <p>{{ flowerDetail.distribution }}</p>
            </div>

            <div class="info-group">
              <h2>特征描述</h2>
              <p>{{ flowerDetail.characteristics }}</p>
            </div>

            <div class="info-group">
              <h2>药用价值</h2>
              <p>{{ flowerDetail.medicinalValue }}</p>
            </div>

            <div class="info-group">
              <h2>保护措施</h2>
              <p>{{ flowerDetail.protectionMeasures }}</p>
            </div>

            <div class="info-group">
              <h2>研究价值</h2>
              <p>{{ flowerDetail.researchValue }}</p>
            </div>
          </div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  name: 'FlowerDetail',
  data() {
    return {
      flowerDetail: {
        name: '',
        category: '',
        region: '',
        description: '',
        habitat: '',
        bloomingSeason: '',
        protectionLevel: '',
        image: '',
        family: '',
        genus: '',
        species: '',
        distribution: '',
        characteristics: '',
        medicinalValue: '',
        protectionMeasures: '',
        researchValue: ''
      }
    };
  },
  created() {
    this.getFlowerDetail();
  },
  methods: {
    async getFlowerDetail() {
      try {
        const id = this.$route.params.id;
        const response = await axios.get(`/flower-detail/${id}`);
        this.flowerDetail = response.data;
      } catch (error) {
        console.error('获取花卉详情失败:', error);
        this.$message.error('获取花卉详情失败，请稍后重试');
      }
    }
  }
};
</script>

<style scoped>
.flower-detail {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

.detail-card {
  margin-bottom: 20px;
}

.detail-header {
  text-align: center;
  margin-bottom: 30px;
}

.detail-header h1 {
  font-size: 2.5rem;
  color: #303133;
  margin-bottom: 15px;
}

.tags {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.detail-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
}

.image-section {
  position: sticky;
  top: 20px;
}

.flower-image {
  width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.info-section {
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.info-group {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 8px;
}

.info-group h2 {
  color: #303133;
  font-size: 1.5rem;
  margin-bottom: 15px;
  border-bottom: 2px solid #409EFF;
  padding-bottom: 10px;
}

.description {
  font-size: 1.1rem;
  color: #606266;
  line-height: 1.6;
  margin-bottom: 20px;
}

.info-item {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  color: #606266;
}

.info-item i {
  margin-right: 10px;
  color: #409EFF;
}

@media (max-width: 768px) {
  .detail-content {
    grid-template-columns: 1fr;
  }

  .image-section {
    position: static;
  }

  .detail-header h1 {
    font-size: 2rem;
  }
}
</style> 